package com.example.sup.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sup.config.SupSchedulingConfigurerOptimize;
import com.example.sup.conttroller.response.ServerResponse;
import com.example.sup.entity.ElectricityConsumptionInfo;
import com.example.sup.exception.CommonQueryException;
import com.example.sup.service.ElectricityConsumptionInfoService;
import com.example.sup.mapper.ElectricityConsumptionInfoMapper;
import com.example.sup.service.PrisonService;
import com.example.sup.vo.ElectricityConsumptionInfoVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author mac
* @description 针对表【electricity_consumption_info】的数据库操作Service实现
* @createDate 2024-07-19 10:05:16
*/
@Service
public class ElectricityConsumptionInfoServiceImpl extends ServiceImpl<ElectricityConsumptionInfoMapper, ElectricityConsumptionInfo>
    implements ElectricityConsumptionInfoService{
    @Resource
    private SupSchedulingConfigurerOptimize supSchedulingConfigurerOptimize;
    @Resource
    private PrisonService prisonService;
    @Override
    public List<ElectricityConsumptionInfoVO> totalElectricityConsumption(Integer prisonId) {
        //1.统计每个监室每天的耗电量
        List<ElectricityConsumptionInfo> electricityConsumptionInfos = baseMapper.totalElectricityConsumptionPercentageByDay(prisonId);
        //2.将entity-----vo
        List<ElectricityConsumptionInfoVO> electricityConsumptionInfoVOList = electricityConsumptionInfos.stream().map(electricityConsumptionInfo -> {
            ElectricityConsumptionInfoVO electricityConsumptionInfoVO = new ElectricityConsumptionInfoVO();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String days = simpleDateFormat.format(electricityConsumptionInfo.getCreateTime());
            electricityConsumptionInfoVO.setDays(days);
            electricityConsumptionInfoVO.setElectricityConsumption(electricityConsumptionInfo.getElectricityConsumption());
            return electricityConsumptionInfoVO;
        }).collect(Collectors.toList());
        if(electricityConsumptionInfoVOList==null||electricityConsumptionInfos.size()<=0){
            throw new CommonQueryException("没有查询到耗电量信息数据");
        }
        return electricityConsumptionInfoVOList;
    }




    }




